﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using carinfor;
using System.Reflection;

namespace 系统设置
{
    public partial class settingform : Form
    {
        carinfor.configIni configini = new carinfor.configIni();


        static SYS_DAL.dbControl dbcontrol = null;
        static string sqlstring = "";
        static string stationid, lineid, czy;

        public settingform()
        {
            String[] CmdArgs = System.Environment.GetCommandLineArgs();
            InitializeComponent();
            if (CmdArgs.Length >= 5)
            {
                sqlstring = CmdArgs[1].Replace("$$$", " ");
                stationid = CmdArgs[2];
                lineid = CmdArgs[3];
                czy = CmdArgs[4];
                dbcontrol = new SYS_DAL.dbControl(sqlstring);
            }
        }
        public static void saveLog<T>(string proname,T preconfig, T nowcofig)
        {
            PropertyInfo[] properties = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (var property in properties)
            {
                string paraname = property.Name;
                object valueA1 = property.GetValue(preconfig, null);
                object valueA2 = property.GetValue(nowcofig, null);

                checkParaChanged(proname,paraname, valueA1, valueA2);
            }
        }
        private static void checkParaChanged(string proname,string paraname, object prevalue, object nowvalue)
        {
            if (prevalue.ToString() != nowvalue.ToString())
            {
                try
                {
                    if (dbcontrol != null)
                    {
                        //dbcontrol.saveParaLog(proname, stationid, lineid, czy, paraname, prevalue.ToString(), nowvalue.ToString(), "");

                    }
                }
                catch (Exception er)
                {
                    MessageBox.Show(er.Message);
                    dbcontrol = null;
                }
            }
        }

        private string version = "";
        private void GetVersion()
        {
            version = "7.1.1237.1";// System.Configuration.ConfigurationManager.AppSettings["Version"].ToString();
        }
        void showControl(Form obj)
        {
            obj.TopLevel = false;
            obj.FormBorderStyle = FormBorderStyle.None;
            this.panelMain.Controls.Clear();
            this.panelMain.Controls.Add(obj);
            obj.Dock = DockStyle.Fill;
            //obj.KeyDown +=new KeyEventHandler(this.settingform_KeyDown);
            obj.Show();
        }
        void initConfigInfo()
        {
            carinfor.equipmentConfigInfdata equipconfig = configini.getEquipConfigIni();
        }
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            string selectednode = e.Node.Name.ToString();
            switch(selectednode)
            {
                case "仪器测功机":
                    {
                        DynSet set = new DynSet();
                        showControl(set);
                    }
                    break;
                case "仪器EV":
                    {
                        EVSet set = new EVSet();
                        showControl(set);
                    }
                    break;
                case "仪器废气分析仪":
                    {
                        //FqySet set = new FqySet();
                        //showControl(set);
                    }
                    break;
                case "仪器流量计":
                    {
                        //LljSet set = new LljSet();
                        //showControl(set);
                    }
                    break;
                case "仪器烟度计":
                    {
                        //YdjSet set = new YdjSet();
                        //showControl(set);
                    }
                    break;
                case "仪器氮氧分析仪":
                    {
                        //NofxySet set = new NofxySet();
                        //showControl(set);
                    }
                    break;
                case "仪器滤纸烟度计":
                    {
                        //LzSet set = new LzSet();
                        //showControl(set);
                    }
                    break;
                case "仪器转速计":
                    {
                        //ZsjSet set = new ZsjSet();
                        //showControl(set);
                    }
                    break;
                case "仪器油温计":
                    {
                        //YwjSet set = new YwjSet();
                        //showControl(set);
                    }
                    break;
                case "仪器其他设备":
                    {
                        LedSet set = new LedSet();
                        showControl(set);
                    }
                    break;
                case "方法稳态工况":
                    {
                        //ASMSet set = new ASMSet();
                        //showControl(set);
                    }
                    break;
                case "方法瞬态工况":
                    {
                        //VmasSet set = new VmasSet();
                        //showControl(set);
                    }
                    break;
                case "方法加载减速":
                    {
                        //LugdownSet set = new LugdownSet();
                        //showControl(set);
                    }
                    break;
                case "方法双怠速":
                    {
                        //SdsSet set = new SdsSet();
                        //showControl(set);
                    }
                    break;
                case "方法不透光":
                    {
                        //ZyjsSet set = new ZyjsSet();
                        //showControl(set);
                    }
                    break;
                case "自检测功机":
                    {
                        //CgjZjSet set = new CgjZjSet();
                        //showControl(set);
                    }
                    break;
                case "自检废气分析仪":
                    {
                        //FqyZjSet set = new FqyZjSet();
                        //showControl(set);
                    }
                    break;
                case "自检流量计":
                    {
                        //LljZjSet set = new LljZjSet();
                        //showControl(set);
                    }
                    break;
                case "自检烟度计":
                    {
                        //YdjZjSet set = new YdjZjSet();
                        //showControl(set);
                    }
                    break;
                case "自检氮氧分析仪":
                    {
                        //NOxfxyZjSet set = new NOxfxyZjSet();
                        //showControl(set);
                    }
                    break;
                case "检测参数":
                    {
                        TestParaSet set = new TestParaSet();
                        showControl(set);
                    }
                    break;
                default:
                    break;
            }
        }

        private void settingform_Load(object sender, EventArgs e)
        {
            initConfigInfo();
            GetVersion();
            labelVersion.Text = version;
        }

        private void settingform_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Shift && e.Control && e.KeyCode == Keys.M)
            {
                foreach(Control con in panelMain.Controls)
                {
                    foreach(Panel panel in con.Controls)
                    {
                        panel.Visible = true;
                    }
                }
            }
        }

    }
}
